package lib

import (
	"encoding/json"
	"os"

	"gitee.com/konyshe/gogo"
)

var (
	configPath = "config.json"
	pConfig    *Config
)

func GetConfig() *Config {
	if pConfig == nil {
		pConfig = new(Config)

		cbyte := gogo.FileReadAll(configPath)
		if cbyte == nil {
			os.Exit(1)
		}

		gogo.CheckErrorExit(json.Unmarshal(cbyte, &pConfig.Config))
	}

	return pConfig
}

func GetConfigData() ConfigType {
	return GetConfig().Config
}

type ConfigType struct {
	SERVER_PORT  int
	LOG_LEVEL    string
	LOG_MAX_SIZE int64
	DATA_SOURCE  string
}

type Config struct {
	Config ConfigType
}
